﻿namespace OrderServiceLevel0.Repositories
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using OrderServiceLevel0.Model;

    public class MemoryRepository : IRepository
    {
        private Dictionary<string, Order> repository = new Dictionary<string, Order>();

        public List<Order> Orders
        {
            get
            {
                return this.repository.Values.ToList();
            }
        }

        public void AddOrder(Order order)
        {
            this.repository.Add(order.Id, order);
        }

        public virtual Order RetrieveOrder(string id)
        {
            return this.repository[id];
        }

        public void RemoveOrder(string id)
        {
            this.repository.Remove(id);
        }

        public void UpdateOrder(Order order)
        {
            if (this.repository.ContainsKey(order.Id))
            {
                this.repository[order.Id] = order;
            }
        }
    }
}